package com.rsk.api.curriculum;


import javax.ws.rs.QueryParam;

import com.rsk.shiro.jwt.JwtUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.aop.ParamCheck;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.curriculum.RskCourseCategoryService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;
import com.rsk.utils.tools.PageUtils;

@RestController
@RequestMapping(value="/rsk/courseCategory")
public class RskCourseCategoryApi {
	
	@Reference(interfaceClass = RskCourseCategoryService.class, protocol = "dubbo")
	private RskCourseCategoryService courseCategoryService;
	
	
	//@RequiresPermissions("coursecategory:save")
	@PostMapping(value="/saveCourseCategory" )
	public Result<String> saveCourseCategory(@QueryParam("categoryName") @ParamCheck(notNull=true) String categoryName,
		   							  @QueryParam("sort") @ParamCheck(notNull=true) Integer sort,
		   							  @QueryParam("pId") @ParamCheck(notNull=true) Long pId,
		   							  @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = courseCategoryService.saveCourseCategory(categoryName, pId, sort, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("coursecategory:update")
	@PostMapping(value="/updateCourseCategory" )
	public Result<String> updateCourseCategory(@QueryParam("id") @ParamCheck(notNull=true) Long id,
										       @QueryParam("categoryName") @ParamCheck(notNull=true) String categoryName,
										       @QueryParam("sort") @ParamCheck(notNull=true) Integer sort,
									           @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = courseCategoryService.updateCourseCategory(id, categoryName, sort, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	//@RequiresPermissions("coursecategory:del")
	@PostMapping(value="/delCourseCategory" )
	public Result<String> delCourseCategory(@QueryParam("id") @ParamCheck(notNull=true) Long id,
									        @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = courseCategoryService.delCourseCategory(id, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("coursecategory:updateSee")
	@PostMapping(value="/updateCourseCategoryIsSee" )
	public Result<String> updateCourseCategoryIsSee(@QueryParam("id") @ParamCheck(notNull=true) Long id,
									                @QueryParam("isSee") @ParamCheck(notNull=true) Integer isSee,
									                @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = courseCategoryService.updateCourseCategorySee(id, isSee, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}

	@SuppressWarnings("rawtypes")
	@PostMapping(value="/selectCourseCategoryByPage" )
	public Result<PageUtils> selectCourseCategoryByPage(
			@QueryParam("nowPage") @ParamCheck(notNull=true) Integer nowPage,
			@QueryParam("pageSize") @ParamCheck(notNull=true) Integer pageSize,
			@QueryParam("categoryName") String categoryName,
			@RequestHeader("Authorization") String Authorization){
		String operatorUser = JwtUtil.getClaim(Authorization, "account");
		PageUtils page = courseCategoryService.selectCourseCategory(categoryName, nowPage, pageSize);
		return ResultBuilder.success(page, ResultCode.SUCCESS);
	}
}
